package com.newly.driver.sdk.device.video.service.impl.tencent;

import cn.hutool.core.lang.Assert;
import com.newly.driver.sdk.device.video.cloud.channel.QueryChannelReq;
import com.newly.driver.sdk.device.video.cloud.channel.QueryChannelResp;
import com.newly.driver.sdk.device.video.exception.NewlyDeviceException;
import com.newly.driver.sdk.device.video.service.api.IChannel;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.iotvideoindustry.v20201201.models.DescribeIPCChannelsRequest;
import com.tencentcloudapi.iotvideoindustry.v20201201.models.DescribeIPCChannelsResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * @author gjm guan
 * @date 2021/10/20 16:20
 * @desc 腾讯云
 */
@Slf4j
public class TencentChannel extends AbstractTencentCloud implements IChannel {

    @Override
    public QueryChannelResp listChannel(QueryChannelReq queryChannelReq) {
        try {
            Assert.notNull(queryChannelReq, "查询通道请求参数异常");
        } catch (IllegalArgumentException e) {
            throw new NewlyDeviceException(e.getMessage());
        }

        // 设置查询通道请求参数
        DescribeIPCChannelsRequest req = new DescribeIPCChannelsRequest();
        req.setDeviceId(queryChannelReq.getDeviceId());
   /*   req.setOffset(1l);
        req.setLimit(10l);
        Long[] types = ArrayUtil.newArray(Long.class, 1);
        types[0] = 1l;
        req.setChannelTypes(types);*/

        // 发起查询通道请求
        DescribeIPCChannelsResponse resp = null;
        try {
            resp = this.httpClient().DescribeIPCChannels(req);
        } catch (TencentCloudSDKException e) {
            throw new NewlyDeviceException("查询云设备通道失败:", e);
        }

        QueryChannelResp queryChannelResp = new QueryChannelResp(resp);

        return queryChannelResp;
    }
}
